import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

public class ParquetReadDecryption {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder()
                .appName("ParquetReadDecryption")
                .master("local[*]")  // 本地运行
                .config("spark.hadoop.parquet.encryption.kms.client.class",
                        "InMemoryKMS")
                .config("spark.hadoop.parquet.encryption.key.list",
                        "footerKey:AAECAwQFBgcICQoLDA0ODw==, columnKey:AAECAwQFBgcICQoLDA0ODw==")
                .config("spark.hadoop.parquet.crypto.factory.class",
                        "org.apache.parquet.crypto.keytools.PropertiesDrivenCryptoFactory")
                .getOrCreate();
        String outputPath = "encrypted_data.parquet";
        Dataset<Row> decryptedData = spark.read().parquet(outputPath);
        System.out.println("读取解密文件：");
        decryptedData.show();

        spark.stop();
    }
}
